-module(helper).
-include_lib ("nitrogen/include/wf.inc").
-include("src/handling/useful.hrl").
-compile(export_all).

runhertz(Command, Arg) ->
    {A, B, C} = now(),
    FileName = ?TMP_DIR ++ integer_to_list(A) ++ integer_to_list(B) ++ integer_to_list(C) ++ ".hz",
    file:write_file(FileName, Arg),
    Output = os:cmd(Command ++ " " ++ FileName),
    os:cmd("rm  " ++ FileName),
    Output.

logged() ->
    Out = case wf:user() of
	undefined ->
 	    Nick = wf_platform:get_cookie(nick),
	    HashedPass = wf_platform:get_cookie(hpass),
 	    Status = wf_platform:get_cookie(status),

 	    case db:validate_member(name, {Nick, HashedPass, Status}) of
 		true ->
 		    wf:user(Nick),
		    wf:session(hpass, HashedPass),
		    wf:session(status, Status),
		    true;
 		false -> false
 	    end;
	SNick ->
 	    db:validate_member(name, {SNick, wf:session(hpass), wf:session(status)})
    end,
    %io:format("~w~n", [Out]),
    Out.

act(Module, PostBack) ->
    [ #event{ delegate=Module, type=click, postback=PostBack}].

id_me() ->
    ID = get(wf_session),
    %io:format("~w~n", [ID]),
    ID.
